/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cardgame.gui;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JPanel;
import cardgame.*;
import cardgame.game.*;
import cardgame.game.monsters.*;
import cardgame.game.spellcards.*;
import com.sun.awt.AWTUtilities;

/**
 *
 * @author Carl
 */
public class CardInfoFrame extends javax.swing.JFrame{

    public CardInfoFrame(){
        setType(Type.UTILITY);
        setUndecorated(true);
        AWTUtilities.setWindowOpaque(this, false);
        initComponents();
        FrameUtil.initWindowSpecials(this);
        getContentPane().setBackground(new Color(80, 80, 80));
        panManaContainer.add(panMana);
        panCardDisplayContainer.add(panCardDisplay);
    }
    private PanCardInfo_Mana panMana = new PanCardInfo_Mana(30);
    private CardDisplay cardDisplay;
    private JPanel panCardDisplay = new JPanel(){{
            setOpaque(false);
        }

        @Override
        protected void paintComponent(Graphics _graphics){
            super.paintComponent(_graphics);
            Graphics2D graphics = (Graphics2D) _graphics;
            if(cardDisplay != null){
                graphics.translate(0, -30);
                PanField.drawCardDisplay(graphics, this, cardDisplay);
            }
        }
    };

    public void setCardDisplay(CardDisplay cardDisplay){
        this.cardDisplay = cardDisplay;
        panMana.setManaAmount(null);
        if((cardDisplay != null) && cardDisplay.isFront()){
            if(cardDisplay.getCard() instanceof MonsterCard){
                MonsterCard monsterCard = (MonsterCard) cardDisplay.getCard();
                panMana.setManaAmount(monsterCard.getSummonCost().getMana());
            }
            else if(cardDisplay.getCard() instanceof SpellCard){
                SpellCard spellCard = (SpellCard) cardDisplay.getCard();
                panMana.setManaAmount(spellCard.getSpell().getCost().getMana());
            }
        }
        panCardDisplay.updateUI();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panManaContainer = new javax.swing.JPanel();
        panCardDisplayContainer = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Card Info");
        setResizable(false);

        panManaContainer.setBackground(new java.awt.Color(80, 80, 80));
        panManaContainer.setOpaque(false);
        panManaContainer.setLayout(new java.awt.GridLayout());

        panCardDisplayContainer.setBackground(new java.awt.Color(80, 80, 80));
        panCardDisplayContainer.setOpaque(false);
        panCardDisplayContainer.setLayout(new java.awt.GridLayout());

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panCardDisplayContainer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGap(29, 29, 29)
                .addComponent(panManaContainer, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(31, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(17, 17, 17)
                .addComponent(panManaContainer, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(panCardDisplayContainer, javax.swing.GroupLayout.DEFAULT_SIZE, 374, Short.MAX_VALUE)
                .addGap(0, 0, 0))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]){
        java.awt.EventQueue.invokeLater(new Runnable(){
            
            @Override
            public void run(){
                Card[] cards = new Card[]{new RagnarosTheFirelord()};
                int x = 0;
                for(Card card : cards){
                    CardInfoFrame cardInfoFrame = new CardInfoFrame();
                    cardInfoFrame.setCardDisplay(new CardDisplay(card){{
                        setIsFront(true);
                    }});
                    cardInfoFrame.setLocation(x, 0);
                    cardInfoFrame.setVisible(true);
                    x += cardInfoFrame.getWidth();
                }
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel panCardDisplayContainer;
    private javax.swing.JPanel panManaContainer;
    // End of variables declaration//GEN-END:variables
}
